 package server;

 import client.MapleCharacter;
 import client.MapleClient;
 import com.alibaba.druid.pool.DruidPooledConnection;
 import database.DatabaseConnection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import tools.MaplePacketCreator;








 public class MapleActivity
 {
/*  22 */   private static final Logger log = LogManager.getLogger(MapleActivity.class.getName());
   private static final int activity_max = 150;
/*  24 */   private static final int[] stage = new int[] { 20, 40, 80, 120, 150 };

   public static void initAllActivity() {
/*  27 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection(); 
/*  28 */         PreparedStatement ps = con.prepareStatement("DELETE FROM missionstatus WHERE missionid >= 120101 AND missionid <= 120114")) {
/*  29 */       ps.executeUpdate();
/*  30 */       ps.close();
     }
/*  32 */     catch (SQLException e) {
/*  33 */       log.error("Error MissionDelete:", e);
     }
   }

   public static void loginTip(MapleClient c) {
     String message;
/*  39 */     int activity = getDiffActivity(c.getPlayer());

/*  41 */     if (activity == 0) {
/*  42 */       message = "#e【今日登陆提示】#n\r\n\r\n已完成所有活跃度任务，可以去试试挑战新BOSS~";
     } else {
/*  44 */       message = "#e【今日登陆提示】#n\r\n\r\n您今天还需 " + getNextStageNeed(c.getPlayer()) + " 活跃度即可领取第 " + getNextStage(c.getPlayer()) + " 阶段奖励。\r\n点击拍卖查看如何获得活跃度。";
     }
/*  46 */     c.announce(MaplePacketCreator.sendHint(message, 150, 60));
   }

   public static int getActivity(MapleCharacter player) {
/*  50 */     int ret = 0;
/*  51 */     for (QuestActivity q : QuestActivity.values()) {
/*  52 */       int times = player.MissionGetFinish(player.getId(), q.id);
/*  53 */       ret += times * q.activity;
     }
/*  55 */     return ret;
   }

   public static void finish(MapleCharacter player, int questid) {
/*  59 */     if (!player.MissionStatus(player.getId(), questid, 0, 4)) {
/*  60 */       player.MissionMake(player.getId(), questid, 0, 0L, 0, 0);
     }
/*  62 */     else if (player.MissionGetFinish(player.getId(), questid) >= QuestActivity.getMaxTimesById(questid)) {
       return;
     }

/*  66 */     player.MissionFinish(player.getId(), questid);
/*  67 */     player.dropSpouseMessage(10, "[系统提示] 任务完成，活跃度增加 " + QuestActivity.getActivityById(questid));
   }

   public static int getMaxActivity() {
/*  71 */     return 150;
   }

   public static int getDiffActivity(MapleCharacter player) {
/*  75 */     return 150 - getActivity(player);
   }

   public static int getNextStage(MapleCharacter player) {
/*  79 */     int stage_ = 0;
/*  80 */     int activity = getActivity(player);
/*  81 */     for (int i = 0; i < stage.length; i++) {
/*  82 */       if (activity < stage[i]) {
/*  83 */         stage_ = i + 1;
         break;
       }
     }
/*  87 */     return stage_;
   }

   public static int getNextStageNeed(MapleCharacter player) {
/*  91 */     return stage[Math.min(stage.length - 1, getNextStage(player) - 1)] - getActivity(player);
   }

   public static int getRecevieReward(MapleCharacter player) {
/*  95 */     int activity = getActivity(player);
/*  96 */     for (int i = 1; i <= stage.length; i++) {
/*  97 */       if (activity >= stage[i - 1] && player.getBossLog("活跃度礼包" + i) == 0) {
/*  98 */         return i;
       }
     }
/* 101 */     return -1;
   }

   public enum QuestActivity {
/* 105 */     每日签到(120101, 5, 1),
/* 106 */     装备砸卷(120102, 2, 5),
/* 107 */     使用魔方(120103, 2, 5),
/* 108 */     废弃任务(120104, 5, 2),
/* 109 */     挑战扎昆(120105, 2, 5),
/* 110 */     挑战品克缤(120106, 10, 1),
/* 111 */     击杀任意BOSS(120107, 10, 1),
/* 112 */     在线300分钟(120108, 5, 1),
/* 113 */     在线800分钟(120109, 10, 1),
/* 114 */     环任务(120110, 1, 20),
/* 115 */     每日红包(120111, 10, 1),
/* 116 */     兑换中介币(120112, 10, 1),
/* 117 */     兑换点券(120113, 10, 1),
/* 118 */     闯关副本(120114, 20, 1);

     private final int id;

     QuestActivity(int id, int activity, int maxtimes) {
/* 123 */       this.id = id;
/* 124 */       this.activity = activity;
/* 125 */       this.maxtimes = maxtimes;
     }
     private final int activity; private final int maxtimes;
     public static int getActivityById(int id) {
/* 129 */       for (QuestActivity q : values()) {
/* 130 */         if (q.id == id) {
/* 131 */           return q.activity;
         }
       }
/* 134 */       return 0;
     }

     public static int getMaxTimesById(int id) {
/* 138 */       for (QuestActivity q : values()) {
/* 139 */         if (q.id == id) {
/* 140 */           return q.maxtimes;
         }
       }
/* 143 */       return 0;
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\server\MapleActivity.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */